package cn.tedu.day01.jnsdlfaq.user.service.impl;

import cn.tedu.day01.jnsdlfaq.user.mapper.SysUserMapper;
import cn.tedu.day01.jnsdlfaq.user.pojo.SysUser;
import cn.tedu.day01.jnsdlfaq.user.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public List<SysUser> selectAll() {
        return null;
    }

    @Override
    public IPage<SysUser> selectUserAll(Page page) {
        return sysUserMapper.selectUserAll(page);
    }

    @Override
    public int addUser(SysUser user) {

        return sysUserMapper.insert(user);
    }

    @Override
    public int updateUser(SysUser user) {
        return sysUserMapper.updateById(user);
    }

    @Override
    public int deleteUser(Integer id) {
        return sysUserMapper.deleteById(id);
    }

    @Override
    public SysUser selectById(Integer id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public SysUser selectByName(String loginName) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("login_name", loginName);
        return sysUserMapper.selectOne(queryWrapper);
    }

    @Override
    public SysUser userLogin(String username, String password) {
        return sysUserMapper.login(username, password);
    }
}
